<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>${sysName}</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="${resRoot}/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="${resRoot}/css/main.css" media="all" />
	<link rel="stylesheet" href="${resRoot}/layui/admin/admin.css" media="all" />
	<style>
	#content:-webkit-full-screen {
 background-color:rgb(255, 255, 12);
}
	</style>
</head>
<body class="childrenBody">
	<div class="layui-fluid layui-row" id="content">  
		<div class="layui-col-md2 layui-card" >
		
		<!-- <div class="layui-card">
		<div class="layui-form layui-card-header layuiadmin-card-header-auto">
		<form id="searchForm1" class="layui-form layui-form-pane" method="post" action=""  >
		<div class="layui-inline">
	      <label class="layui-form-label">门牌</label>
	      <div class="layui-input-block">
	        <input type="text" class="layui-input" id="doorName" onkeyup="AutoMatch(this)" placeholder="快速定位门牌" autocomplete="off" >
	      </div>
	    </div>
	    	<a class="layui-btn location_search_btn layui-btn-sm" onclick="AutoMatch(doorName);" >定位</a>
	    	<button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="AutoMatch();" >清除</button>
		</div>
		</form>
		</div> -->
		
      <div id="doorTree" class="ztree" style="height:570px;overflow: auto;" ></div>
    </div>
    
    <div class="layui-col-md10" >
    
          <div class="layui-card">
	<div class="layui-form layui-card-header layuiadmin-card-header-auto">
	<form id="searchForm" class="layui-form layui-form-pane" method="post" action="#"  >
		<input type="hidden" id="dataId" name="parentId" value="" >
		
		<div class="layui-inline">
			    <label class="layui-form-label">组织名称</label>
			    <div class="layui-input-block">
				      <input type="text" name="name" id="name" value="<#if deptDTO?? && deptDTO.name?? >${deptDTO.name!}</#if>"  autocomplete="off" placeholder="请输入组织名称" class="layui-input">
			    </div>
			  </div>
		  
	    
		<div class="layui-inline">
		    <button class="layui-btn search_btn" id=""  lay-submit="" lay-filter="searchDataBtn"  type="button">查询</button>
		</div>
		<div class="layui-inline">
			<a class="layui-btn linksAdd_btn" style="background-color:#5FB878" href="javascript:void(0);" onclick="openWin('${base}/sys/dept/input',null,'添加');">添加</a>
			
		</div>
		</form>
		<div class="layui-form-item">
		
	<div class="layui-form member_list" style="margin-top: 10px;" >
	  	
	  	<table class="layui-hide" id="test" lay-filter="demo" ></table>
		<script type="text/html" id="barDemo">
		  <a class="layui-btn layui-btn-xs" lay-event="detail">查看</a>
		  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
		  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
		</script>
	</div>
	
    </div>
	</div>
	
	</div>
	
	</div>
	</div>
	<#include "/page/footer.html">
	<script src="${resRoot}/js/fullscreen.js"></script>
	<link href="${resRoot}/jquery-ztree/3.5.40/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css"/>
	<script src="${resRoot}/jquery-ztree/3.5.40/js/jquery.ztree.all.min.js" type="text/javascript"></script>
	<script>
	var setting = {check:{enable:true,chkStyle: "radio",radioType:"all"},view:{selectedMulti:false},
			data:{simpleData:{enable:true,idKey:"id",pIdKey:"parentId"},key:{name:"name"}},callback:{
				onAsyncSuccess: zTreeOnAsyncSuccess,
				beforeCheck:zTreeOnClick,
				beforeClick:function(id, node){
				tree.checkNode(node, !node.checked, true, true);
				// console.log(node)
				return false;
			}
			}};
	function zTreeOnAsyncSuccess(event, treeId, treeNode, msg) {
		console.log(treeId)
		alert(treeId);
	}
	function zTreeOnClick(event, treeId, treeNode) {
		var data = treeId.id;
		$("#dataId").val(data);
		$(".search_btn").click();
	}
	
	var treeJson;

	  $.ajax({
			type : "post",
			url : "${base}/sys/dept/getZTree",
			data : {},
			dataType : "json",
			async : false,
			success : function(data) {
				treeJson= data.message;
				// console.log(treeJson)
			}
		}); 
	// 用户-菜单
	var zNodes=treeJson;
	// 初始化树结构
	var tree = $.fn.zTree.init($("#doorTree"), setting, zNodes);
	// 不选择父节点
	//tree.setting.check.chkboxType = { "Y" : "ps", "N" : "s" };
	tree.setting.check.radioType = "all";

	// 默认选择节点
	var ids = "";
	for(var i=0; i<ids.length; i++) {
		var node = tree.getNodeByParam("id", ids[i]);
		try{tree.checkNode(node, true, false);}catch(e){}
	}
	// 默认展开全部节点
	// tree.expandAll(false);
	showZtreeNum(true, tree, 1);
	function openFirstTreenode(){
	    /* 获取所有树节点 */
	    var nodes = tree.transformToArray(tree.getNodes());
	    // 关闭所有节点
	    for (var i = 0, length_1 = nodes.length; i < length_1; i++) {
	    	tree.expandNode(nodes[i], false);//第二个参数为false证明是折叠
	    }
	    //展开第一级节点
	    tree.expandNode(nodes[0], true);//第二个参数为true证明是展开
	}

	function showZtreeNum(status,childnodes,level){
		// 调用时首次调用是showZtreeNum(true,zTree,classLevel) 获取总的结点
		// 然后递归调用其孩子结点
		if(status){
		var rootnodes = tree.getNodes();
		showZtreeNum(false,rootnodes,level);//递归
		}else{
		if(childnodes){
		var len=childnodes.length;
		if(level<childnodes[0].level+1){
		return;
		}
		for (var i = 0; i < len; i++) {
			tree.expandNode(childnodes[i], true, false, false, true);
		var child=childnodes[i].children;
		showZtreeNum(false,child,level);//递归
		}
		}
		}
		}
	
	

	var table;
	layui.use(['table', 'form'], function(){
		form = layui.form,
	  table = layui.table;
	  
	  table =  $.extend(table, {config: {checkName: 'checked'}});
	  table.render({
	    elem: '#test'
	    ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
    	,defaultToolbar: ['filter', 'print']
	    ,url:'${base}/sys/dept/getPageData'
	    ,where:{
	    	
	    }
	    ,cols: [[
	    // 默认不开启合计，需要使用时自行开启合计功能， 并在render添加参数 totalRow: true  例如url:'https://www.layui.com/doc/modules/table.html#options'，在需要开启合计的行中添加 totalRow: true
	    // {type:'checkbox', fixed: true, disabled:true,totalRowText: '合计', checkbox:false},
	    { type: 'numbers', title: '序号', width: 80, fixed: 'left' },
			{field:'name', width:120, title: '组织名称'},
			{field:'code', width:120, title: '组织编码'},
			{field:'parentName', width:120, title: '上级组织'},
			{field:'type', width:120, title: '组织类型',templet:function(row){
		    	  return getDictLable("dept_type",row.type);
		      }},
			{field:'createBy', width:120, title: '创建人',hide:true},
			{field:'updateBy', width:120, title: '更新人',hide:true},
	      {fixed: 'right', width: 260, align:'center',title: '操作', toolbar: '#barDemo'}
	    ]]
	    ,loading:true
	    ,page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
		      layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
		      ,curr: 1 //设定初始在第 5 页
		      ,groups: 5 //只显示 5 个连续页码
		      ,first: true //显示首页
		      ,last: true //显示尾页
	}
	      ,parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
	    	  console.log(res)
	        return {
	          "code": res.message.code, //解析接口状态
	          "msg": res.message.msg, //解析提示文本
	          "count": res.message.count, //解析数据长度
	          "data": res.message.data //解析数据列表
	        };
	      }
	  });
	  
	      
	      var reloadTable = function (data) {
	          table.reload("test", { //此处是上文提到的 初始化标识id
	              where: data
	              ,page: { 
			      layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
			      ,curr: 1
			      ,groups: 5 //只显示 5 个连续页码
			      ,first: true //显示首页
			      ,last: true //显示尾页
				}
	          });
	      };

	  
	//监听表格复选框选择
	  table.on('checkbox(demo)', function(obj){
		  console.log(obj.data)
	  });
	  
	  form.on('submit(searchDataBtn)', function(data){
			reloadTable(data.field)
	    });
	  
	  //监听工具条
	  table.on('tool(demo)', function(obj){
	    var data = obj.data;
	    if(obj.event === 'detail'){
	      var url = "${base}/sys/dept/detial";
	      openWin(url,data.id,'查看详情');
	    } else if(obj.event === 'del'){
	        del(data.id);
	    } else if(obj.event === 'edit'){
	    	var url = "${base}/sys/dept/input";
	        openWin(url,data.id,'修改详情');
	    } else if (obj.event==='deptVillage') {
	    	var url = "${base}/sys/dept/toSaveVillage";
	        openWin(url,data.id,'设置小区');
	    }
	  });
	});
	
	document.onkeydown = function (event) {
        var e = event || window.event;
        if (e && e.keyCode == 13) { //回车键的键值为13
        	$(".search_btn").click(); //调用登录按钮的登录事件
        }
    }; 
	
	  		function del(id){	
	  			layer.confirm('确定删除该条数据吗?', function(index){
  				 $.ajax({
  		    		 type : "post",
  		    		 url : "${base}/sys/dept/del",
  		    		 data : {
  		    			  id : id
  		    			 },
  					 dataType : "json",
  					 async : false,
  					 success : function(data) {
  						 flag  = data.message;
  							if(flag != 0) {
  								layer.msg('删除成功！', {
  									  icon: 1,
  									  time: 2000 //2秒关闭（如果不配置，默认是3秒）
  									}, function(){
  									  //do something
  										window.location.reload();
  									});  

  								
  							} else {
  								layer.alert("数据错误，请完善数据！");
  							}
  					 }
  		    	 });
  			});
		}
	  		
	  		function importExcel() {
	  			var url = "${base}/sys/dept/toImport";
	  			var titleStr = "数据导入";
	  	        var index = layui.layer.open({
	  	            title : titleStr,
	  	            type : 2,
	  	            content : url,
	  	            success : function(layero, index){
	  	                var body = layui.layer.getChildFrame('body', index);
	  	                setTimeout(function(){
	  	                    layui.layer.tips('点击此处返回', '.layui-layer-setwin .layui-layer-close', {
	  	                        tips: 3
	  	                    });
	  	                },500)
	  	            }
	  	        })
	  	        layui.layer.full(index);
	  	        //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
	  	        $(window).on("resize",function(){
	  	            layui.layer.full(index);
	  	        })
	  		}

			function showPhoto(url) {
			var jsonstr = "{'title':'','id':123,'start':0,'data':[{'alt':'图1','pid':666,'src':'" + url +"','thumb':''}]}";
			var json = eval('(' + jsonstr + ')');
			layer.photos({
			photos: json
			,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
			});
			}
			
</script>
</body>
</html>